﻿#include "txr_algo_dlm_seg_v2.h"
#include "infer_seg_v2.h"

namespace txr_algo_dlm_seg
{
	TxrAlgoDlmSegV2::TxrAlgoDlmSegV2()
		:m_p_infer(TK_NULL_PTR)
	{

	}

	TxrAlgoDlmSegV2::~TxrAlgoDlmSegV2()
	{
		Release();
	}

	tk_bool TxrAlgoDlmSegV2::Load(st_dlm_cfg& cfg)
	{
		Release();
		m_p_infer = new InferSegV2();

		std::string path_weight = std::string(cfg.file_path_name) + ".seg2";

		return m_p_infer->Init(cfg.gpu_id, path_weight.c_str());
	}

	void TxrAlgoDlmSegV2::Release()
	{
		SAFE_DELETE(m_p_infer);
	}

	void TxrAlgoDlmSegV2::Detect(st_detect_unit* p_unit, tk_int32 size)
	{
		if (!size)
		{
			return;
		}
		for (tk_int32 i = 0; i < size; ++i)
		{
			st_img_rgb& rgb = p_unit[i].img;
			if (!
				((rgb.pp_rgb8[0] && rgb.pp_rgb8[1] && rgb.pp_rgb8[2]) ||
					(rgb.pp_rgb16[0] && rgb.pp_rgb16[1] && rgb.pp_rgb16[2]) ||
					(rgb.pp_rgbf[0] && rgb.pp_rgbf[1] && rgb.pp_rgbf[2]))
				)
			{
				Q_ASSERT(0);
				return;
			}
		}
		m_p_infer->Detect(p_unit, size);
	}
	//===========================================
	extern "C" TXR_ALGO_DLM_SEGMENT_V2_EXPORT TxrAlgoDlmSegImpl * CreateDlmSegObj();
	extern "C" TXR_ALGO_DLM_SEGMENT_V2_EXPORT void DeleteDlmSegObj(TxrAlgoDlmSegImpl * p);
	TxrAlgoDlmSegImpl* CreateDlmSegObj()
	{
		return new TxrAlgoDlmSegV2();
	}

	void DeleteDlmSegObj(TxrAlgoDlmSegImpl* p)
	{
		SAFE_DELETE(p);
	}
}//namespace txr_algo_dlm